package com.inspur.security.cbb3.kms.keymanager.secrets.repository;

import com.inspur.security.cbb3.kms.keymanager.secrets.po.SecretsBean;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 密钥信息表
 * @author lijunchang
 */
public interface SecretsRepository extends JpaRepository<SecretsBean, String>, JpaSpecificationExecutor<SecretsBean> {
    /**
     *
     * 根据密钥名称、创建人id进行查询
     * @param name          密钥名称
     * @param deleted       是否删除
     * @param creatorId     创建人id
     * @return  密钥数量
     */
    long countByNameAndDeletedAndCreatorIdOrderByCreatedTimeDesc(String name,Boolean deleted,String creatorId);

    /**
     *
     * 根据密钥名称、公私钥、创建人id进行查询
     * @param name          密钥名称
     * @param deleted       是否删除
     * @param note  密钥是公钥还是私钥
     * @param creatorId     创建人id
     * @return  密钥数量
     */
    long countByNameAndDeletedAndNoteAndCreatorIdOrderByCreatedTimeDesc(String name,Boolean deleted,String note,String creatorId);

    /**
     * 根据deleted字段查询
     * @param deleted
     * @return
     */
    List<SecretsBean> findByDeleted(Boolean deleted);

    /**
     * 根据deleted字段删除
     * @param deleted
     * @return
     */
    List<SecretsBean> deleteByDeleted(Boolean deleted);
}
